
function v2click()
{
	document.getElementById('v1').style.display="none";
	document.getElementById('v2').style.display="block";
}

function v1click()
{
	document.getElementById('v2').style.display="none";
	document.getElementById('v1').style.display="block";
}

function sqr()
{
	var n, z, str;
	str = document.getElementById('txtNumber').value;
	n = Number(str);
	n = n * n;
	z = String(n);
	if(z != "NaN")
		document.getElementById('txtNumber').value = z;
	else
		document.getElementById('txtNumber').value = "Please enter a number";
}

function clrscr()
{
	document.getElementById('txtNumber').value = "0";
}

function tosrc()
{
	document.getElementById('v1').style.display="none";
	document.getElementById('v3').style.display="block";
}

function getTemp()
{
	var xmlHttp;
	var html;
	var url, temp, loc;

	url = "http://www.timeanddate.com/worldclock/city.html?n=" + document.getElementById("txtWhere").value;
	xmlHttp = new XMLHttpRequest();
	xmlHttp.onreadystatechange = function()
	{
		if(xmlHttp.readyState == 0)
			document.getElementById('txtTemp').value = "Initializing...";
		if(xmlHttp.readyState == 1 || xmlHttp.readyState == 2 )
			document.getElementById('txtTemp').value = "Loading...";
				
		if(xmlHttp.readyState == 4)
		{
			html = xmlHttp.responseText;
			temp = parse(html);
			loc = findWhere(html);

			document.getElementById('location').innerHTML = "";
			document.getElementById('location').innerHTML = loc;
			document.getElementById('txtTemp').value = temp;
		}
	}

	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function parse(str)
{
	var where, retVal;
	
	where = str.indexOf("Temperature");
	where += 21;
	
	retVal = str.charAt(where) + str.charAt(where + 1);

	return retVal;
}

function findWhere(str)
{
	var start, end, retVal, i;
	retVal = "";
	start = str.indexOf("<title>");
	end = str.indexOf("</title>");
	start += 29;
	for(i = start; i < end; i++)
		retVal += str.charAt(i);
	
	return retVal;
}
